<?php
/**
 * Created by 王跃达.
 * User: 小马出行
 * Date: 2017/8/24
 * Time: 16:17
 */

namespace app\api\model;


use think\Db;
use think\Model;

class FirstModel extends Model
{


    public function __construct()
    {
        parent::__construct();

    }

    /**
     * 根据Uid zone获取首单优惠
     */
    public function getFirstByUidAndZone($uid, $zone_id)
    {
        $where['zone_id'] = array(array("eq", 0), array("eq", $zone_id),"or");
        $where['start_time'] = array("elt", time());
        $where['end_time'] = array("gt", time());
        $first = Db::name("first")->where($where)->find();
        if (!empty($first)) {
            /*
             * 1代表任意时间段乘坐过无优惠，0代表活动期间乘坐过无优惠
             */
            if ($first['is_only_one'] == 0) {
                $map['uid']=$uid;
                $map['order_status']=array("gt",20);
                $map['first_price']=array("gt",0);
                $map['order_time']=array("egt",$first['start_time']);
            }else{
                $map['uid']=$uid;
                $map['first_price']=array("gt",0);
                $map['order_status']=array("gt",20);
            }
            $is_use=Db::name("order_common")->field("common_id")->where($map)->find();
            if(!empty($is_use)){
                return array();
            }

        }
        return $first;
    }


}